<template>
  <view
    class="bg-white w-screen h-screen fixed !z-[999999999999] inset-0 flex flex-col justify-center items-center gap-6"
  >
    <image src="/static/dddr105.png" mode="aspectFill" class="size-20" />
    <view class="text-[.875rem] text-[#5C6068]">网络连接已断开，请检查网络设置</view>

    <view
      class="w-[7.625rem] h-[2rem] bg-[#00A9AB] flex justify-center items-center rounded-full"
      @click="goToSettings"
    >
      <view class="text-[.875rem] text-[#FFFFFF]">点击重试</view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        // key: value
        isConnected: true
      }
    },
    mounted() {
      let that = this
      // 初始化平台信息
      // 初始化平台信息
      that.isIOS = uni.getSystemInfoSync().platform === 'ios'
      uni.onNetworkStatusChange(function (res) {
        let isConnected = res.isConnected
        vk.setVuex('$app.networkType', isConnected)
        console.log('isConnected==> ', isConnected)
        if (isConnected) {
          that.reconnect()
          vk.myfn.getLocation()
        }
      })
    },
    methods: {
      goToSettings() {
        // 参考 uView 组件的实现
        // this.openSystemSettings()
        this.reconnect()
      },

      openSystemSettings() {
        // 以下方法来自5+范畴，如需深究，请自行查阅相关文档
        // https://ask.dcloud.net.cn/docs/
        if (this.isIOS) {
          this.gotoiOSSetting()
        } else {
          this.gotoAndroidSetting()
        }
      },

      gotoiOSSetting() {
        var UIApplication = plus.ios.import('UIApplication')
        var application2 = UIApplication.sharedApplication()
        var NSURL2 = plus.ios.import('NSURL')
        var setting2 = NSURL2.URLWithString('App-prefs:root=General')
        application2.openURL(setting2)
        plus.ios.deleteObject(setting2)
        plus.ios.deleteObject(NSURL2)
        plus.ios.deleteObject(application2)
      },

      gotoAndroidSetting() {
        var Intent = plus.android.importClass('android.content.Intent')
        var Settings = plus.android.importClass('android.provider.Settings')
        var mainActivity = plus.android.runtimeMainActivity()
        var intent = new Intent(Settings.ACTION_SETTINGS)
        mainActivity.startActivity(intent)
      },

      reconnect() {
        // this.$emit('reconnects')
        vk.myfn.reloadPage()
      }
    }
  }
</script>

<style lang="scss" scoped></style>
